# 通过get获取字典的值
person = {"name": "jackie", "age": 100}
age = person.get("age", 10)
print("age=", age)


# 统计单词频率
text = "11 22 33 44 55 apple banana apple orange banana apple 11 33 44 55 22 purple red apple"
words = text.split()
print("words=", words)

dicts = {item: item for item in words}  # 把列表转为字典
print("把数组转换为字典=", dicts)

statistic_num_count = {}
for item in words:
    statistic_num_count[item] = statistic_num_count.get(item, 0) + 1


# 通过推导式和数组中统计
new_num_count_dict = {item: words.count(item) for item in words}


print(
    "statistic_num_count=",
    statistic_num_count,
    "\nnew_num_count_dict=",
    new_num_count_dict,
)
